package com.kaiwukj.android.ufamily.mvp.ui.page.home.home;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.FriendRecoResult;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class RecoFriendChildAdapter extends BaseQuickAdapter<FriendRecoResult, BaseViewHolder> {

    public RecoFriendChildAdapter() {
        this(new ArrayList<>());
    }

    public RecoFriendChildAdapter(List<FriendRecoResult> list) {
        super(R.layout.item_home_attention_friend_child, list);
        addChildClickViewIds(R.id.btn_attention);
    }

    public void postAttention(int userId) {
        for (int i = 0; i < getData().size(); i++) {
            if (userId == getData().get(i).getUserId()) {
                removeAt(i);
                break;
            }
        }
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, FriendRecoResult friendRecoResult) {
        holder.setText(R.id.tv_name, friendRecoResult.getNickName());
        ImageView ivAvatar = holder.getView(R.id.iv_avatar);
        holder.setText(R.id.tv_desc, "来自家院里");
        Glide.with(getContext())
                .load(friendRecoResult.getHeadImg())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(ivAvatar);
    }
}
